package com.itheima.mapper;

import com.itheima.domain.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;
/*
    映射配置类
 */
public interface UserMapper {
    //查询所有
    @Select("select * from user")//statement对象
    List<User> findAll();
    //新增
    @Insert("insert into user values (id,#{username},#{pwd},#{age},#{sex},#{hobby})")
    void saveUser(User user);
    //修改
    @Insert("update user set username=#{username},pwd=#{pwd} where id = #{id}")
    void updateUser(User user);
    //删除
    @Delete("delete  from user where id = #{id} ")//statement对象
    void deleteUser(Integer id);
    //新增
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    @Insert("insert into user values (null,#{username},#{pwd},#{age},#{sex},#{hobby})")
    void saveUsers(User user);
}
